/**
 * 
 */
package com.axt.dbaudit.action.cfg;

import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import com.axt.dbaudit.bean.cfg.EmailCfgBean;
import com.axt.dbaudit.model.cfg.EmailCfg;
import com.axt.soa.action.BaseAction;
import com.axt.soa.msg.types.MsgParam;

/**
 * @author wangyl
 * 
 */
public class EmailCfgAction extends BaseAction {
	private EmailCfgBean emailCfgBean = new EmailCfgBean();

	private List<EmailCfg> emailCfgs = null;

	@JSON(name = "emailcfgs")
	public List<EmailCfg> getEmailCfgs() {
		return emailCfgs;
	}

	public void setEmailCfgs(List<EmailCfg> emailCfgs) {
		this.emailCfgs = emailCfgs;
	}

	@JSON(name = "errcode")
	public int getErrcode() {
		return errcode;
	}

	@JSON(name = "errinfo")
	public String getErrinfo() {
		return errinfo;
	}

	private String au_UserName; // 邮件服务器
	private String au_port; // 端口号
	private String au_host; // 用户名
	private String au_Faddress; // 发件人地址
	private String au_Taddress; // 收件人地址
	private String au_Passwd; // 密码

	/**
	 * @return the au_UserName
	 */
	public String getAu_UserName() {
		return au_UserName;
	}

	/**
	 * @param au_UserName
	 *            the au_UserName to set
	 */
	public void setAu_UserName(String au_UserName) {
		this.au_UserName = au_UserName;
	}

	/**
	 * @return the au_port
	 */
	public String getAu_port() {
		return au_port;
	}

	/**
	 * @param au_port
	 *            the au_port to set
	 */
	public void setAu_port(String au_port) {
		this.au_port = au_port;
	}

	/**
	 * @return the au_host
	 */
	public String getAu_host() {
		return au_host;
	}

	/**
	 * @param au_host
	 *            the au_host to set
	 */
	public void setAu_host(String au_host) {
		this.au_host = au_host;
	}

	/**
	 * @return the au_Faddress
	 */
	public String getAu_Faddress() {
		return au_Faddress;
	}

	/**
	 * @param au_Faddress
	 *            the au_Faddress to set
	 */
	public void setAu_Faddress(String au_Faddress) {
		this.au_Faddress = au_Faddress;
	}

	/**
	 * @return the au_Taddress
	 */
	public String getAu_Taddress() {
		return au_Taddress;
	}

	/**
	 * @param au_Taddress
	 *            the au_Taddress to set
	 */
	public void setAu_Taddress(String au_Taddress) {
		this.au_Taddress = au_Taddress;
	}

	/**
	 * @return the au_Passwd
	 */
	public String getAu_Passwd() {
		return au_Passwd;
	}

	/**
	 * @param au_Passwd
	 *            the au_Passwd to set
	 */
	public void setAu_Passwd(String au_Passwd) {
		this.au_Passwd = au_Passwd;
	}

	/**
	 * 获取邮件配置
	 */
	public String queryEmailCfg() {
		setEmailCfgs(emailCfgBean.queryEmailCfg(serverPath));
		setErrcode(emailCfgBean.getErrcode());
		setErrinfo(emailCfgBean.getErrinfo());

		return MsgParam.SUCCESS;
	}

	/**
	 * 更改邮件配置
	 */
	public String updateEmailCfg() {

		EmailCfg emailCfg = new EmailCfg();
		emailCfg.setAu_host(au_host);
		emailCfg.setAu_port(au_port);
		emailCfg.setAu_UserName(au_UserName);
		emailCfg.setAu_Passwd(au_Passwd);
		emailCfg.setAu_Faddress(au_Faddress);
		emailCfg.setAu_Taddress(au_Taddress);

		emailCfgBean.updateEmailCfg(serverPath, emailCfg);
		setErrcode(emailCfgBean.getErrcode());
		setErrinfo(emailCfgBean.getErrinfo());

		return MsgParam.SUCCESS;
	}
}
